<?php
if (!defined('CMS_SYSTEM')) die();

/*
 * Du an trang Thalad phan banner
 * Le duc vien
 */
function themeBanner() 
{
	global $start_time, $db, $prefix, $currentlang,$path_upload;
	list($img_banner) = $db->sql_fetchrow($db->sql_query("SELECT images FROM ".$prefix."_gentext WHERE textname='footmsg' AND alanguage='$currentlang'"));
		echo "<div id=\"banner\">";
			echo "<div class=\"content\">";
			$bnext = Common::getExt($img_banner);
            if($bnext == "swf") {
            	echo "<embed width=\"980\" height=\"115\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"transparent\" allowfullscreen=\"false\" scale=\"noborder\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" quality=\"high\" src=\"$path_upload/temp/$img_banner\" />";
            }else{
					echo "<img src=\"$path_upload/temp/$img_banner\" width=\"980\" height=\"115\" />";
            }
			echo "</div>";
		echo "</div>";
}
function themeMenu()
{
	global $db, $currentlang, $prefix, $imgFold ;
	
	$result_menu = $db->sql_query("SELECT mid, title, url FROM {$prefix}_mainmenus WHERE  parentid='0' AND active='1' and alanguage='$currentlang' Order by weight asc");
	echo "<div id=\"head\">";
			echo "<div class=\"content\">";
				echo "<div class=\"w720 fl fix\">";
					echo "<div id=\"navigation\" class=\"navigation fl\">";
					    if($db->sql_numrows($result_menu) > 0) 
	                    {
	                    	$i=1;
							echo "<ul>";
							while (list($mid, $title_menu, $url_menu) = $db->sql_fetchrow($result_menu)) 
		                    {
		                    	if($i==1)
		                    	{
		                    		$class='root active';
		                    	}
		                    	else{$class='root';}
		                        echo "<li class=\"level\"><a href=\"$url_menu\" class=\"$class\">$title_menu</a>";
		                        $result_check = $db->sql_query("SELECT mid, title, url FROM {$prefix}_mainmenus WHERE parentid=$mid and active=1 and alanguage='$currentlang' order by weight asc");
		                        if($db->sql_numrows($result_check) > 0) 
	                            {
	                            	$ii=1;
	                            	echo "<ul>";
	                            	while (list($mid, $title_menu, $url_menu) = $db->sql_fetchrow($result_check)) 
		                            {
				                            if($ii==$db->sql_numrows($result_check))
					                    	{
					                    		$iiclass='last';
					                    	}
					                    	else{$iiclass='';}
									         echo "<li class=\"$iiclass\"><a href=\"$url_menu\">$title_menu</a>";
									             $result_sub = $db->sql_query("SELECT mid, title, url FROM {$prefix}_mainmenus WHERE parentid=$mid and active=1 and alanguage='$currentlang' order by weight asc");
									             if($db->sql_numrows($result_sub) > 0) 
	                                             {
	                                             	$iii=1;
	                                             	echo "<ul>";
	                                             	while (list($mid, $title_menu, $url_menu) = $db->sql_fetchrow($result_sub)) 
		                                            {
		                                            if($iii==$db->sql_numrows($result_sub))
							                    	{
							                    		$iiiclass='last';
							                    	}
							                    	else{$iiiclass='';}
		                                            	echo "<li class=\"$iiiclass\"><a href=\"$url_menu\">$title_menu</a></li>";
		                                            	$iii++;
		                                            }
		                                            echo "</ul>";
	                                             }
									         echo "</li>";
									         $ii++;
		                            }
		                             echo "</ul>";
	                            }
	                            echo "</li>";
	                           $i++;
		                    }
		                    
							echo "</ul>";
							
	                    }
						echo "<div class=\"clear\"></div>";
					echo "</div>";
					include_once("modules/products/Cart.class.php");
					$cart = new Cart(CART_SESS);
					$newCart = $cart->getData();
                    $cart_count=count($newCart);
					echo "<div class=\"cart fr\">";
						echo "<div class=\"l\"></div>";
						echo "<div class=\"r\"></div>";
						echo "<div class=\"m\">";
							echo "<a href=\"".url_sid("index.php?f=products&do=views")."\">"._VIEW_CART_COUNT.": <span class=\"f1\">$cart_count</span></a>";
						echo "</div>";
					echo "</div>";
				echo "</div>";
				echo "<div class=\"w250 fr\">";
					echo "<div class=\"search\">";
						echo '<form method="POST" action="'.url_sid("index.php?f=search")."\" name=\"frmSearch\" onsubmit=\"return frmSubmit()\">";
							echo "<input type=\"text\" name=\"keyword\" value=\""._VIEW_SERACH_DATA."\" class=\"txt\"  onfocus=\"javascript:if(this.value=='"._VIEW_SERACH_DATA."'){this.value='';};\" onblur=\"javascript:if(this.value!='"._VIEW_SERACH_DATA."'){this.value='"._VIEW_SERACH_DATA."';}\"/>";
							echo "<input type=\"submit\" value=\"\" class=\"btnSearch\"/>";
						echo "</form>";
					echo "</div>";
				echo "</div>";
			echo "</div>";
		echo "</div>";
}
function themeFlash()
{
	global $start_time, $db, $prefix, $currentlang,$path_upload;
	list($img_home) = $db->sql_fetchrow($db->sql_query("SELECT homeimg FROM ".$prefix."_gentext WHERE textname='footmsg' AND alanguage='$currentlang'"));
	echo "<div class=\"w720 fl\">";
					echo "<div class=\"flash\">";
                        $bnext = Common::getExt($img_home);
			            if($bnext == "swf") {
			            	echo "<embed width=\"716\" height=\"446\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"transparent\" allowfullscreen=\"false\" scale=\"noborder\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" quality=\"high\" src=\"$path_upload/temp/$img_home\" />";
			            }else{
								echo "<img src=\"$path_upload/temp/$img_home\"/images/banner.jpg\" width=\"716\" height=\"446\" />";
			            }
					echo "</div>";
	echo "</div>";
}
function themeRightCategory()
{
	global $db, $currentlang, $prefix;
	echo "<div class=\"module mb10\" id=\"module_category\">";
						echo "<div class=\"title tc\">";
							echo "<div class=\"text ico1\">";
								echo "<span>"._CATEGORY_RIGHT."</span>";
							echo "</div>";
						echo "</div>";
						echo "<div class=\"wrap\">";
						$result = $db->sql_query("SELECT mid, title, url FROM {$prefix}_leftmenus WHERE parentid=0 and active=1 and alanguage='$currentlang' order by weight asc");
						if($db->sql_numrows($result) > 0) 
						{
							$i=1;
							echo "<ul class=\"ul_category\">";
							while (list($mid, $title, $url) = $db->sql_fetchrow($result)) 
							{
							    if($i==1)
		                    	{
		                    		$classleft='cate active';
		                    	}
		                    	else{$classleft='cate';}
								echo "<li><a href=\"$url\" class=\"$classleft\">$title</a>";
								$result_sub = $db->sql_query("SELECT mid, title,url FROM {$prefix}_leftmenus WHERE parentid=$mid and active=1 and alanguage='$currentlang' order by weight asc");
								if($db->sql_numrows($result_sub) > 0) 
								{
								  echo "<ul class=\"ul_subcate\">";
								  while (list($mid_sub, $title_sub,$url) = $db->sql_fetchrow($result_sub)) 
								  {
									echo "<li><a href=\"$url\">$title_sub</a></li>";
								  }
								  echo "</ul>";
								}
								echo "</li>";
								$i++;
							}
							echo "</ul>";
						}
						echo "</div>";
	echo "</div>";
}
function themeLinkWebsite()
{
	global $db, $currentlang, $prefix;
	echo "<div class=\"module mb10\" id=\"module_link\">";
						echo "<div class=\"title tc\">";
							echo "<div class=\"text ico2\">";
								echo "<span>"._MULTIPLE_LINK."</span>";
							echo "</div>";
						echo "</div>";
						echo "<div class=\"wrap\">";
							echo "<div class=\"link\">";
								echo "<select class=\"select\" onchange=\"webLink(this)\">";
									echo "<option value=\"\">"._SELECT_LINKS."</option>";
									$result = $db->sql_query("SELECT id,title, links, times FROM {$prefix}_links WHERE if_show=1 and alanguage='$currentlang' order by times desc");
									if($db->sql_numrows($result) > 0) 
									{
										while (list($id,$title, $links, $times) = $db->sql_fetchrow($result)) 
							            {
							            		echo "<option value=\"$links\">$title</option>";							            	
							            }
									}
								echo "</select>";
							echo "</div>";
						echo "</div>";
	echo "</div>";
}
function themeLang()
{
	global $Default_Temp;
	echo "<div class=\"module mb10\" id=\"module_language\">";
						echo "<div class=\"title tc\">";
							echo "<div class=\"text ico3\">";
								echo "<span>"._LANGUAGE."</span>	";
							echo "</div>";
						echo "</div>";
						echo "<div class=\"wrap\">";
							echo "<div class=\"language fix\">";
								echo "<a href=\"".url_sid("index.php?&lang=vietnamese")."\" class=\"fl\">";
									echo "<img src=\"templates/".$Default_Temp."/images/langVn.gif\" align=\"absmiddle\"/>&nbsp;&nbsp; Việt nam";
								echo "</a>";
								echo "<a href=\"".url_sid("index.php?&lang=english")."\" class=\"fr\">";
									echo "<img src=\"templates/".$Default_Temp."/images/langEn.gif\" align=\"absmiddle\"/>&nbsp;&nbsp; England";
								echo "</a>";
							echo "</div>";
						echo "</div>";
	echo "</div>";
}
function themeCount()
{
	global $db, $currentlang, $prefix;
	$ngaygio = time();
	$trinhduyet = $_SERVER['HTTP_USER_AGENT'];
	$ip = $_SERVER['REMOTE_ADDR'];
	if ( !isset($_SESSION['ONLINE']) )
	{
		$ngaygio = time();
		$trinhduyet = $_SERVER['HTTP_USER_AGENT'];
		$ip = $_SERVER['REMOTE_ADDR'];
		
		$db->sql_query("INSERT INTO ".$prefix."_online (times, internet,addressip) VALUES ($ngaygio,'$trinhduyet','$ip')");
		
		$_SESSION['ONLINE'] = 1;
	}
	$number = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_online"));
    $total = ($number[0]) ? $number[0] : 1;
    $array = str_split($total);
	echo "<div class=\"module\" id=\"module_stats\">";
						echo "<div class=\"title tc\">";
							echo "<div class=\"text ico4\">";
								echo "<span>"._VIEW_WEBSITE."</span>";
							echo "</div>";
						echo "</div>";
						echo "<div class=\"wrap\">";
							echo "<div class=\"stats tc\">";
								echo "<ul class=\"ul_stats\">";
								foreach ($array as &$value) {
									echo "<li>$value</li>";
								}	
								echo "</ul>";
							echo "</div>";
						echo "</div>";
	echo "</div>";
}
function themeSlideShow($bnid)
{
	global $db, $prefix, $path_upload, $currentlang, $module_name;
	$result = $db->sql_query("SELECT bwidth, bheight, abs, type FROM ".$prefix."_advertise_banners WHERE active='1' AND bnid='$bnid'");
 	if($db->sql_numrows($result) > 0) {
		list($bwidth, $bheight, $absbn, $bntype) = $db->sql_fetchrow($result);
		if($bntype == 0) {
			$result_bn = $db->sql_query("SELECT id, target, images, imgtext, module,links FROM ".$prefix."_advertise WHERE bnid='$bnid' AND active='1' ORDER BY weight");
		} else {
			$result_bn = $db->sql_query("SELECT id, target, images, imgtext, module,links FROM ".$prefix."_advertise WHERE bnid='$bnid' AND active='1' ORDER BY rand() DESC");
	}
	echo "<div class=\"content\">";
				echo "<div class=\"slide tl\">";
					echo "<div class=\"slide-nav\">";
						echo "<div class=\"slide-nav-clip\">";
						if ($db->sql_numrows($result_bn) > 0) {
							echo "<ul>";
							while (list($mid_sub, $target,$images,$imgtext,$module,$links) = $db->sql_fetchrow($result_bn)) 
							 {
							 	$bmod_arr = @explode("|",$module);
								if($module == "all" || (in_array("home",$bmod_arr) && ($home == 1)) || in_array($module_name,$bmod_arr)) 
							    {
										$bnext = Common::getExt($images);
									 	if($target == 1) {
											$bntarget ="_blank";
										} else {
											$bntarget = "_self";
										}
										if($bnext == "swf") {
											echo "<li>";
											   echo "<a href=\"$links\" target=\"$bntarget\" title=\"$imgtext\">";
											      echo "<embed width=\"$bwidth\" height=\"$bheight\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"transparent\" allowfullscreen=\"false\" scale=\"noborder\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" quality=\"high\" src=\"$path_upload/adv/$images\" title=\"$imgtext\"/>";
											   echo "</a>";
											echo "</li>";
										}else 
										{
									 	   echo "<li><a href=\"$links\" target=\"$bntarget\" title=\"$imgtext\"><img src=\"$path_upload/adv/$images\" width=\"$bwidth\" height=\"$bheight\" alt=\"[Alternative text]\" /></a></li>";
		
										}
							    }
							 }
						    echo "</ul>";
						}
						echo "</div>";
						echo "<div class=\"slide-nav-btn slide-nav-prev\"><a href=\"#\" title=\""._VIEW_SCROLL_LEFT."\"><span>Previous</span></a></div>";
						echo "<div class=\"slide-nav-btn slide-nav-next\"><a href=\"#\" title=\""._VIEW_SCROLL_RIGHT."\"><span>Next</span></a></div>";
					echo "</div>";
				echo "</div>";		
	echo "</div>";
}
function themeFooter()
{
	global $start_time, $db, $prefix, $currentlang;
	list($footmsg) = $db->sql_fetchrow($db->sql_query("SELECT content FROM ".$prefix."_gentext WHERE textname='footmsg' AND alanguage='$currentlang'"));
	echo "<div class=\"content footer fix\">";
				echo "<p class=\"copyright\">$footmsg</p>";
	echo "</div>";
}
}
?>